using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class MoneyPanel : MonoBehaviour
{
    public static MoneyPanel Instance = null;

    private TextMeshProUGUI coinText;
    private TextMeshProUGUI menuText;

    public void Init()
    {
        if (Instance == null) Instance = this;
        transform.Find("CoinButton").GetComponent<Button>().onClick.AddListener(OnAddClick);
        transform.Find("ReturnButton").GetComponent<Button>().onClick.AddListener(OnReturnBtnClick);
        coinText = transform.Find("CoinButton/Text").GetComponent<TextMeshProUGUI>();
        menuText = transform.Find("ReturnButton/MenuText").GetComponent<TextMeshProUGUI>();
        RefreshMoney();
    }

    public void OnAddClick()
    {
        GameManager.Instance.PlayBtnClickAudio();
        TipPanel.Instance.ShowPanel("免费金币", "观看广告获得 ￥2000 。", null,
            () => { AdManager.ShowVideo(() => { GameManager.Instance.AddCoin(2000); }); },
            "取 消", "观看广告");
        //AndroidTool.single.CallAdEvent(AndroidToolEnum.OnAdd, OnAddBack);
    }

    public void OnReturnBtnClick()
    {
        GameManager.Instance.PlayBtnClickAudio();
        switch (GameManager.Instance.panelState)
        {
            case PanelState.MainMenu:
                TipPanel.Instance.ShowPanel("退出", "确认退出游戏", () => { AdManager.Quit(); }, null, "确 认", "取 消");
                break;
            case PanelState.Store:
                GameManager.Instance.SetPanelState(PanelState.MainMenu);
                break;
            case PanelState.LevelSelections:
                GameManager.Instance.SetPanelState(PanelState.Store);
                break;
        }
    }

    public void SetMenuTitle(PanelState panelState)
    {
        switch (panelState)
        {
            case PanelState.MainMenu:
                menuText.text = $"主页面";
                break;
            case PanelState.Store:
                menuText.text = $"商店";
                break;
            case PanelState.LevelSelections:
                menuText.text = $"选择任务";
                break;
            default:
                menuText.text = $"游戏";
                break;
        }
    }

    public void RefreshMoney() => coinText.text = $"￥{GameManager.Instance.Coin.ToString()}";

    public void SetPanelActive(bool isActive) => gameObject.SetActive(isActive);
}